
namespace FastFood.Business.Logic
{
	using System;
    using System.Data.Linq;
	using System.Collections.Generic;
	using EDOSwit.Entity;
	using FastFood.Business.Entities;
	using FastFood.DataAccess;
    using System.Linq;

	/// <summary>
	/// Represents the Manager of Insumos.
	/// </summary>
	[Serializable]
	public class InsumosManager : Singleton<InsumosManager>
	{
        #region Methods

        /// <summary>
        /// Selects all records from the Insumos table by vendidle atributte and nombre or unidad.
        /// </summary>
        public IList<Insumos> ListarByNombreOrUnidad(string nombre, string unidades)
        {
            try
            {
                return InsumosData.Instancia.ListarByNombreOrUnidad(nombre, unidades).Reverse().ToList();                
            }
            catch (Exception) { throw; }
        }

        /// <summary>
        /// Selects all records from the Insumos table by vendidle atributte and nombre or unidad.
        /// </summary>
        public IList<Insumos> ListarByNombreOrUnidadAndVendible(string nombre, string unidades, bool vendible)
        {
            try
            {
                return InsumosData.Instancia.ListarByNombreOrUnidadAndVendible(nombre, unidades, vendible).Reverse().ToList();
            }
            catch (Exception) { throw; }
        }

        /// <summary>
        /// Selects all records from the Insumos table by vendidle atributte.
        /// </summary>
        public IList<Insumos> ListarByVendible(bool vendible)
        {
            try
            {
                return InsumosData.Instancia.ListarByVendible(vendible).Reverse().ToList();
            }
            catch (Exception) { throw; }
        }

        /// <summary>
        /// Selects all records from the Insumos table by vendidle atributte.
        /// </summary>
        public IList<Insumos> ListarSemiPreparados()
        {
            try
            {
                return InsumosData.Instancia.ListarSemiPreparados().Reverse().ToList();
            }
            catch (Exception) { throw; }
        }

        /// <summary>
        /// Selects all records from the Insumos table by vendidle atributte.
        /// </summary>
        public IList<Insumos> ListarSemiPreparados(string nombre)
        {
            try
            {
                var insumos = InsumosData.Instancia.ListarSemiPreparados();
                if (!string.IsNullOrEmpty(nombre))
                {
                    insumos = insumos.Where(p => p.nombre.StartsWith(nombre)).ToList();
                }
                return insumos;
            }
            catch (Exception) { throw; }
        }

        /// <summary>
        /// Selects all records from the Insumos table by vendidle atributte.
        /// </summary>
        public IList<Insumos> ListarInsumos()
        {
            try
            {
                return InsumosData.Instancia.ListarInsumos().Reverse().ToList();
            }
            catch (Exception) { throw; }
        }

		/// <summary>
		/// Selects all records from the Insumos table.
		/// </summary>
        public IList<Insumos> Listar()
        {
            try
            {
                return InsumosData.Instancia.Listar().Reverse().ToList();
            }
            catch (Exception) { throw; }
        }

		/// <summary>
		/// Selects a single record from the Insumos table.
		/// </summary>
		public Insumos Obtener(short insumoID)
		{
			try
			{
				return InsumosData.Instancia.Obtener(insumoID);
			}
			catch (Exception) { throw; }
        }

        /// <summary>
        /// Selects a single record from the Insumos table.
        /// </summary>
        public Insumos ObtenerSemiTerminado(short semiTerminadoID)
        {
            try
            {
                Insumos semiTerminado = InsumosData.Instancia.Obtener(semiTerminadoID);
                semiTerminado.SemiProductos_Insumos1 = new EntitySet<SemiProductos_Insumos>();
                semiTerminado.SemiProductos_Insumos1.AddRange(SemiProductos_InsumosData.Instancia.ListarPorSemiProductoID(semiTerminadoID));
                return semiTerminado;
            }
            catch (Exception) { throw; }
        }

		/// <summary>
		/// Saves a record to the Insumos table.
		/// </summary>
		public short Agregar(Insumos insumos)
		{
			try
			{
                return InsumosData.Instancia.Agregar(insumos);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Updates a record in the Insumos table.
		/// </summary>
		public bool Modificar(Insumos insumos)
		{
			try
            {
                return InsumosData.Instancia.Modificar(insumos);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Deletes a record from the Insumos table by its primary key.
		/// </summary>
		public bool Eliminar(short insumoID)
		{
			try
			{
				return InsumosData.Instancia.Eliminar(insumoID);
			}
			catch (Exception) { throw; }
        }

        /// <summary>
        /// Saves a record to the Insumos table.
        /// </summary>
        public short AgregarSemiTerminado(Insumos semiTerminado)
        {
            try
            {
                return InsumosData.Instancia.AgregarSemiTerminados(semiTerminado);
            }
            catch (Exception) { throw; }
        }

        /// <summary>
        /// Updates a record in the Insumos table.
        /// </summary>
        public bool ModificarSemiTerminado(Insumos semiTerminado)
        {
            try
            {
                return InsumosData.Instancia.ModificarSemiTerminados(semiTerminado);
            }
            catch (Exception) { throw; }
        }

        /// <summary>
        /// Deletes a record from the Insumos table by its primary key.
        /// </summary>
        public bool EliminarSemiTerminado(short semiTerminadoID)
        {
            try
            {
                return InsumosData.Instancia.Eliminar(semiTerminadoID);
            }
            catch (Exception) { throw; }
        }

		#endregion
	}
}
